
import { observable, action, extendObservable, isObservable, toJS } from 'mobx';
import * as smsTempApi from '../../apis/smsTemp';
import moment from 'moment';
import { WeaTableNew } from 'comsMobx';

const { TableStore } = WeaTableNew;
export default class SmsTempStore {
    @observable comsWeaTableStore = new TableStore();

  // 用于控制传给weatable的sessionkey
    @observable dataKey = '0';

    @observable loading = false;

    @observable addWithMsg = false;

	@observable showFlag = false;

	@observable dataid = '';

    @observable showEdit = false;

    @action
	setDataId = (dataid = '') => {
		this.dataid = dataid;
	}

	@action
	saveTemp(params) {
		return smsTempApi.saveTemp(params);
	}

	@action
    doDel(params) {
      return smsTempApi.doDel(params);
    }

    @action
    setLoading(newBool = false) {
        this.loading = newBool;
	}

    @action doLoading = () => {
        // 在搜索开始前应该有进度条表示数据正在加载
        this.setLoading(true);
        smsTempApi.getList().then((data) => {
        	this.comsWeaTableStore.getDatas(data.sessionkey, 1);
            this.dataKey = data.sessionkey;
            this.setLoading(false); // 加载完数据清除进度条
        });
    }

	// 打开弹窗
    @action
    openTempList() {
        this.showFlag = true;
    }

    @action
    closeTempList() {
        this.showFlag = false;
	}

	@action showTempData = (id) => {
        this.addWithMsg = false;
		this.dataid = id;
		this.showEdit = true;
    }

    @action showTempDataAndMsg = () => {
        this.addWithMsg = true;
        this.showEdit = true;
    }

	@action closeTempData() {
		this.showEdit = false;
	}

	@action viewSms = params => smsTempApi.getData(params)
 }
